﻿using UnityEngine;
using strange.extensions.mediation.impl;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.context.api;

public class MediatorView : Mediator 
{
	[Inject]
	public BtnView btnView{ get; set;}

	[Inject(ContextKeys.CONTEXT_DISPATCHER)]
	public IEventDispatcher dispatcher{ get; set;}

	[Inject]
	public ScoreModel scoreModel{ get; set;}

	public override void OnRegister ()
	{
		btnView.Init ();
		dispatcher.AddListener (MediatorEvent.ScoreChange, OnScroreChange);
		dispatcher.AddListener (MediatorEvent.ClickDown, OnClickDown);
		//dispatcher发起命令
		dispatcher.Dispatch (CommandEvent.RequsetScore);
	}


	public override void OnRemove ()
	{
		dispatcher.RemoveListener (MediatorEvent.ScoreChange, OnScroreChange);
		dispatcher.RemoveListener (MediatorEvent.ClickDown, OnClickDown);
	}

	public void OnScroreChange(IEvent evt)
	{
		//btnView.UpdateScore (scoreModel.Score);
		btnView.UpdateScore ((int)evt.data);
	}

	public void OnClickDown()
	{
		dispatcher.Dispatch (CommandEvent.UpdateScore);
	}
}
